package com.zl.easybuy.web;

import com.zl.easybuy.bo.ProductBo;
import com.zl.easybuy.pojo.Product;
import com.zl.easybuy.service.ProductCategoryService;
import com.zl.easybuy.service.ProductService;
import com.zl.easybuy.util.Pages;
import com.zl.easybuy.vo.ProductCategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/Product")
public class ProductController {
    @Autowired
    ProductService productService;
    @Autowired
    ProductCategoryService productCategoryService;

    @RequestMapping("/queryProductDeatil")
    //商品详情页
    public String queryProductDeatil(Integer id, Model model) {
        Product product = new Product();
        product = productService.findProductById(id);
        List<ProductCategoryVo> productCategoryVoList =productCategoryService.findAllCategory();
        model.addAttribute("productCategoryVoList",productCategoryVoList);
        model.addAttribute("product", product);
        return "forward:/pre/product/productDeatil.jsp";
    }

    @RequestMapping("/queryProductList")
    /**
     * 根据分类展示商品列表，搜素实现
     */
    public String queryProductList(Integer category,Integer level, String keyWord, @RequestParam(defaultValue = "1") Integer pageNo, Model model) {
        Pages<Product> pages=productService.findProductList(category,level,keyWord,pageNo);
        model.addAttribute("pager",pages);
        model.addAttribute("keyword",keyWord);
        List<ProductCategoryVo> productCategoryVoList =productCategoryService.findAllCategory();
        model.addAttribute("productCategoryVoList",productCategoryVoList);
        return "forward:/pre/product/queryProductList.jsp";
    }

}
